﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace xjjxmm.infrastructure.compont;

public class CorsCompont : ICompont
{
    public int Order { get; set; } = 400;

    public bool Regist(WebApplicationBuilder builder) {
        //跨域
        builder.Services.AddCors(setupAction =>
        {
            setupAction.AddDefaultPolicy(policy =>
            {
                policy//.WithOrigins("http://localhost:8008")
                    .AllowAnyOrigin()
                    //.AllowCredentials()
                    .AllowAnyHeader()
                    //.WithMethods("OPTION", "POST", "GET");
                    .AllowAnyMethod()
                    ;
                //.AllowCredentials();
            });
        });

        return false;
    }

    public bool Use(WebApplication app)
    {
        app.UseCors();

        return true;
    }
}
